/*     */ package nc.bs.bd.pfxx.plugin;
/*     */ 
/*     */ import java.util.ArrayList;
/*     */ import java.util.Arrays;
/*     */ import java.util.List;
/*     */ import nc.bs.framework.common.NCLocator;
/*     */ import nc.bs.pfxx.ISwapContext;
/*     */ import nc.bs.pfxx.plugin.AbstractPfxxPlugin;
import nc.bs.trade.business.HYPubBO;
/*     */ import nc.itf.bd.supplier.baseinfo.ISupplierBaseInfoService;
/*     */ import nc.md.persist.framework.IMDPersistenceQueryService;
/*     */ import nc.md.persist.framework.IMDPersistenceService;
/*     */ import nc.md.persist.framework.MDPersistenceService;
/*     */ import nc.vo.bd.supplier.SupLinkmanVO;
/*     */ import nc.vo.bd.supplier.SupplierVO;
/*     */ import nc.vo.bd.supplier.finance.SupFinanceVO;
/*     */ import nc.vo.ml.NCLangRes4VoTransl;
/*     */ import nc.vo.pfxx.auxiliary.AggxsysregisterVO;
/*     */ import nc.vo.pfxx.util.ArrayUtils;
/*     */ import nc.vo.pfxx.util.PfxxPluginUtils;
/*     */ import nc.vo.pub.BusinessException;
/*     */ import nc.vo.pub.SuperVO;
/*     */ import nccloud.commons.lang.StringUtils;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class SupplierPfxxPlugin
/*     */   extends AbstractPfxxPlugin
/*     */ {
/*     */   private IMDPersistenceQueryService mdQryService;
/*     */   private IMDPersistenceService mdService;
/*     */   private ISupplierBaseInfoService basesService;
/*     */   
/*     */   protected Object processBill(Object vo, ISwapContext swapContext, AggxsysregisterVO aggvo) throws BusinessException {
/*  37 */     SupplierVO supplierVO = (SupplierVO)vo;
/*  38 */     if (!hasUniqueDefaultLinkMan(supplierVO)) {
/*  39 */       throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("bdpub", "0bdpub0060"));
/*     */     }
/*     */     
/*  42 */     String voPk = PfxxPluginUtils.queryBillPKBeforeSaveOrUpdate(swapContext.getBilltype(), swapContext.getDocID());
/*  43 */     setVOStatus(supplierVO.getSuplinkman(), 2);
			// TT
			if("TT".equals(swapContext.getSender())) {
                String sqlWhere = " NVL(dr,0) = 0 \n" +
                        "   AND name = '" + supplierVO.getName() + "' \n";// ????
				Object voOldPk = this.getHYPubBO().findColValue("bd_supplier", "pk_supplier", sqlWhere);// ????
				if(voOldPk != null) {
					return voOldPk;
				}
				String sqlWhere1 = " NVL(dr,0) = 0 \n" +
						"   AND code = '" + supplierVO.getCode() + "' \n";// ????
				Object voOldPk1 = this.getHYPubBO().findColValue("bd_supplier", "pk_supplier", sqlWhere1);// ????
				if(voOldPk1 != null) {
					return voOldPk1;
				}
			}
 

/*  44 */     if (voPk == null) {
/*  45 */       supplierVO.setStatus(2);
/*  46 */       SupFinanceVO[] supFinanceVo = supplierVO.getSupfinance();
/*     */       
/*  48 */       if (supFinanceVo != null && supFinanceVo.length > 0) {
/*  49 */         for (int i = 0; i < supFinanceVo.length; i++) {
/*  50 */           if (StringUtils.isBlank(supFinanceVo[i].getPk_org())) {
/*  51 */             supFinanceVo[i] = null;
/*     */           }
/*  53 */           supplierVO.setSupfinance(supFinanceVo);
/*     */         } 
/*     */       }
/*  56 */       supplierVO.setSource(Integer.valueOf(1));
/*  57 */       SupplierVO newsupplierVO = getBasesService().pfxxInsertSupplierVO(supplierVO, false);
/*  58 */       voPk = newsupplierVO.getPk_supplier();
/*  59 */       PfxxPluginUtils.addDocIDVsPKContrast(swapContext.getBilltype(), swapContext.getDocID(), voPk);
/*     */     } else {
/*  61 */       supplierVO.setStatus(1);
/*  62 */       setUpdateValues(supplierVO, voPk);
/*  63 */       getBasesService().pfxxUpdateSupplierVO(supplierVO, false);
/*     */     } 
/*  65 */     return voPk;
/*     */   }
/*     */   
/*     */   private boolean hasUniqueDefaultLinkMan(SupplierVO supplier) {
/*  69 */     if (supplier.getSuplinkman() == null || supplier.getSuplinkman().length == 0) {
/*  70 */       return true;
/*     */     }
/*  72 */     int i = 0;
/*  73 */     for (SupLinkmanVO linkMan : supplier.getSuplinkman()) {
/*  74 */       if (linkMan.getIsdefault() != null && linkMan.getIsdefault().booleanValue()) {
/*  75 */         i++;
/*     */       }
/*     */     } 
/*  78 */     return !(i > 1);
/*     */   }
/*     */   
/*     */   private void setVOStatus(SuperVO[] vos, int status) {
/*  82 */     if (ArrayUtils.isEmpty(vos)) {
/*     */       return;
/*     */     }
/*  85 */     for (SuperVO vo : vos) {
/*  86 */       vo.setStatus(status);
/*     */     }
/*     */   }
/*     */   
/*     */   private void setUpdateValues(SupplierVO updateDocVO, String pk) throws BusinessException {
/*  91 */     Object[] objs = getMdQryService().queryBillOfVOByPKsWithOrder(SupplierVO.class, new String[] { pk }, new String[] { "suplinkman" });
/*     */     
/*  93 */     if (ArrayUtils.isEmpty(objs)) {
/*  94 */       throw new BusinessException(
/*  95 */           NCLangRes4VoTransl.getNCLangRes().getStrByID("bdpub", "0bdpub0057"));
/*     */     }
/*  97 */     SupplierVO oldDocVO = (SupplierVO)objs[0];
/*     */     
/*  99 */     updateDocVO.setPk_supplier_v(oldDocVO.getPk_supplier_v());
/* 100 */     updateDocVO.setCreator(oldDocVO.getCreator());
/* 101 */     updateDocVO.setCreationtime(oldDocVO.getCreationtime());
/* 102 */     updateDocVO.setModifier(oldDocVO.getModifier());
/* 103 */     updateDocVO.setModifiedtime(oldDocVO.getModifiedtime());
/* 104 */     updateDocVO.setDataoriginflag(oldDocVO.getDataoriginflag());
/* 105 */     updateDocVO.setPrimaryKey(pk);
/*     */     
/* 107 */     updateDocVO.setPk_oldsupplier(pk);
/* 108 */     updateDocVO.setTs(oldDocVO.getTs());
/* 109 */     List<SupLinkmanVO> linkManVOList = new ArrayList<SupLinkmanVO>();
/* 110 */     if (oldDocVO.getSuplinkman() != null) {
/* 111 */       for (SupLinkmanVO linkManVO : oldDocVO.getSuplinkman()) {
/* 112 */         linkManVO.setStatus(3);
/* 113 */         linkManVOList.add(linkManVO);
/*     */       } 
/*     */     }
/* 116 */     if (updateDocVO.getSuplinkman() != null) {
/* 117 */       linkManVOList.addAll(Arrays.asList(updateDocVO.getSuplinkman()));
/*     */     }
/* 119 */     updateDocVO.setSuplinkman(linkManVOList.toArray(new SupLinkmanVO[0]));
/*     */   }
/*     */   
/*     */   private IMDPersistenceQueryService getMdQryService() {
/* 123 */     if (this.mdQryService == null) {
/* 124 */       this.mdQryService = MDPersistenceService.lookupPersistenceQueryService();
/*     */     }
/* 126 */     return this.mdQryService;
/*     */   }
/*     */   
/*     */   private ISupplierBaseInfoService getBasesService() {
/* 130 */     if (this.basesService == null) {
/* 131 */       this.basesService = NCLocator.getInstance().lookup(ISupplierBaseInfoService.class);
/*     */     }
/* 133 */     return this.basesService;
/*     */   }
/*     */   
/*     */   private IMDPersistenceService getMdService() {
/* 137 */     if (this.mdService == null) {
/* 138 */       this.mdService = MDPersistenceService.lookupPersistenceService();
/*     */     }
/* 140 */     return this.mdService;
/*     */   }

			private HYPubBO pubBO = null;
			
			private HYPubBO getHYPubBO()
			{
				if (pubBO == null)
				{
					pubBO = new HYPubBO();
				}
				return pubBO;
			}
/*     */ }


/* Location:              D:\NC\Home\xmxz\home20240629\module\\uapbd\META-INF\li\\uapbd_pub.jar!/nc/bs/bd/pfxx/plugin/SupplierPfxxPlugin.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.0.7
 */